/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VocSymbTest2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;



/**
 *
 * @author StiggieBig
 */
public class ItemSetFamily implements Iterable<ItemSet>{
    
    SortedSet<ItemSet> itemSetFamily;	//	currently keeping for possible
    									//	generalizations
    ArrayList<ItemSet> itemSetList;
    
    //  default constructor
    public ItemSetFamily(){
        itemSetFamily = new TreeSet<ItemSet>(new ItemSetComparator<ItemSet>());
        itemSetList = new ArrayList<ItemSet>();
    }
    
    //  constructor
    public ItemSetFamily(ItemSet itemSet){
        itemSetFamily = new TreeSet<ItemSet>(new ItemSetComparator<ItemSet>());
        itemSetList = new ArrayList<ItemSet>();
        if(itemSetFamily.add(itemSet)){
        	itemSetList.add(itemSet);
        }
    }
    
    //  copy constructor
    public ItemSetFamily(ItemSetFamily itemSetFamilyToCopy){
        itemSetFamily = new TreeSet<ItemSet>(new ItemSetComparator<ItemSet>());
        itemSetList = new ArrayList<ItemSet>();
        for(ItemSet itemSet : itemSetFamilyToCopy.itemSetList){
        	this.add(itemSet);
        }
    }
    
    public boolean add(ItemSet itemSet){
    	boolean addGood = false;
    	if(itemSetFamily.add(itemSet)){
    		itemSetList.add(itemSet);
    		addGood = true;
    	}
    	return addGood;
    }
    
    public void clear(){
    	itemSetFamily.clear();
    	itemSetList.clear();
    }
    
    /*public ItemSet last(){
    	return itemSetFamily.last();
    }*/
    
    public void PrintSet(){
    	System.out.print('{');
        for (ItemSet itemSet : itemSetFamily) {
        	itemSet.Print();
            if(itemSet != itemSetFamily.last()){
            	System.out.print(", ");
            }
        }
        System.out.print('}');
    }
    
    public void PrintList(){
        int count = 0;
        for (ItemSet itemSet : itemSetList) {
            System.out.print("I");
            System.out.print(count);
            System.out.print(" = ");
            itemSet.Print();
            System.out.printf(", Cardinality: %d", itemSet.size());
            System.out.println();
            count++;
        }
    }
    
	@Override
	public Iterator<ItemSet> iterator() {
		return itemSetList.iterator();
	}
}
